package com.ytc.content.controller;

import com.ytc.commons.model.dto.CourseAuditDto;
import com.ytc.commons.model.dto.CourseBaseDto;
import com.ytc.commons.model.dto.CourseDto;
import com.ytc.commons.model.dto.PageRequest;
import com.ytc.commons.model.vo.CourseBaseVo;
import com.ytc.commons.model.vo.CourseVo;
import com.ytc.commons.model.vo.ResponseResult;
import com.ytc.commons.utils.BeanHelper;
import com.ytc.content.domain.CourseBase;
import org.springframework.web.bind.annotation.*;
import com.ytc.content.service.CourseBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 课程基本信息前端控制器
 * </p>
 */
@Slf4j
@RestController
@RequestMapping("/course")
public class CourseBaseController {

    @Autowired
    private CourseBaseService  courseBaseService;

    /**
     * 分页查询课程数据
     * 请求路径：POST  /course/list?pageNo=1&pageSize=10
     * 请求参数：
     *    Query参数：PageRequest
     *    Body参数：CourseDto
     * 响应数据：
     *    ResponseResult<CourseBase>
     */
    @PostMapping("/list")
    public ResponseResult list(PageRequest request, @RequestBody CourseDto dto) {
        return courseBaseService.courseList(request,dto);
    }


    //上传课程封面图片/
    // *
    // post upload
    // 请求参数：uploadFile（文件）
    //响应内容 ResponseResult<String>
    // */
    @PostMapping("/upload")
    public ResponseResult<String> upload(MultipartFile uploadFile) throws Exception{
        return courseBaseService.upload(uploadFile);
    }

    /*
    * 保存课程
    * post
    * 请求参数CourseBaseDto
    * 返回：ResponseResult<CourseBaseVo>
    * */
    @PostMapping
    public ResponseResult<CourseBaseVo> saveCourseBase(@RequestBody CourseBaseDto dto){
        return courseBaseService.saveCourseBase(dto);

    }

    /*
     * 删除课程（逻辑删除）
     * delete
     * 请求参数course/{courseId}
     * 返回：ResponseResult<null>
     * */
    @DeleteMapping("/{courseId}")
    public ResponseResult deleteById(@PathVariable("courseId") Long courseId){
        courseBaseService.updateStatus(courseId);
        return ResponseResult.okResult();
    }

    /*
    * 编辑回填效果
    * 根据id查询课程信息
    * 请求：GET /{courseBaseId}
    * /参数：地址参数，id
    * 响应ResponseResult<CourseVo>
    * */
    @GetMapping("/{courseBaseId}")
    public ResponseResult<CourseVo> findByCourseId(@PathVariable("courseBaseId") Long courseBaseId){

        CourseBase courseBase =courseBaseService.getById(courseBaseId);
        CourseVo courseVo = BeanHelper.copyProperties(courseBase, CourseVo.class);

        return ResponseResult.okResult(courseVo);
    }

    /*
    *课程根据id更新
    * 请求PUT
    *请求参数：CourseBaseDto
    * 响应：ResponseResult<课程ID>
    * */
    @PutMapping
    public ResponseResult<CourseBaseVo> updateCourse(@RequestBody CourseBaseDto dto){

        return courseBaseService.updateCourse(dto);
    }

    /*
    * //机构提交审核
    * GET commit/{courseBaseId}
    * 返回：ResponseResult
    *
    * */
    @GetMapping("commit/{courseBaseId}")
    public ResponseResult commit(@PathVariable("courseBaseId") Long courseBaseId){
        return courseBaseService.commit(courseBaseId);

    }

    /*
    * //管理端平台审核
    * POST /approve
    * */
    @PostMapping("approve")
    public ResponseResult approve(@RequestBody CourseAuditDto dto){
        return courseBaseService.approve(dto);
    }


    /**
     * 根据课程表id查询课程
    @GetMapping("/{courseBaseId}")
    public ResponseResult findByIdCourse(@PathVariable("courseBaseId") Long courseBaseId){
        CourseBase courseBase = courseBaseService.getById(courseBaseId);
        CourseVo courseVo = BeanHelper.copyProperties(courseBase, CourseVo.class);
        return ResponseResult.okResult(courseVo);
    }*/
}
